
<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card class="tree-card">
        <tree-tools :tree-data="company" :is-root="true"></tree-tools>
        <el-tree :data="data" :props="{ label: 'name', children: 'children' }">
          <tree-tools
            slot-scope="{ data }"
            :tree-data="data"
            @updateList="initData"
          ></tree-tools>
        </el-tree>
      </el-card>
    </div>
  </div>
</template>

<script>
import { tranListToTreeData } from '@/utils'
import { getDepartmenListApi } from '@/api/department'
import TreeTools from './components/tree-toole.vue'
export default {
  name: 'Departments',
  components: {
    TreeTools
  },
  data() {
    return {
      company: { name: '传智教育', manager: '负责人' },
      data: []
    }
  },
  created() {
    this.initData()
  },
  methods: {
    async initData() {
      const { companyName, depts } = await getDepartmenListApi()
      this.company.name = companyName
      this.data = tranListToTreeData(depts, '')
      // console.log(res)
    }
  }
}
</script>

<style>
.tree-card {
  padding: 30px 140px;
  font-size: 14px;
}
</style>
